package com.care.wardmate.remote.factory;

import com.care.common.core.domain.Result;
import com.care.common.core.result.PageResult;
import com.care.wardmate.common.domain.Article;
import com.care.wardmate.common.request.ArticleRequest;
import com.care.wardmate.remote.ArticleRemoteService;
import org.slf4j.Logger;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: 靳家振
 * @Date: 2024/3/26 19:09
 * @Description:
 **/

@Component
public class ArticleRemoteServiceFallbackFactory implements FallbackFactory<ArticleRemoteService> {
    public final static Logger logger = org.slf4j.LoggerFactory.getLogger(ArticleRemoteServiceFallbackFactory.class);
    @Override
    public ArticleRemoteService create(Throwable cause) {
        logger.error ("远程调用失败，原因：{}", cause.getMessage());
        return new ArticleRemoteService () {
            @Override
            public Result<PageResult<Article>> selectArticle(ArticleRequest articleRequest) {
                return Result.error ("病友圈列表服务错误，请联系管理员");
            }

            @Override
            public Result<Article> selectArticleById(Integer articleId) {
                return Result.error("病友圈列表详情错误,请联系管理员");
            }
        };
    }
}
